package com.elh.jvm.classpath;

import cn.hutool.core.util.StrUtil;

import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 递归获取文件
 *
 * @author liulei
 **/
public class CompositeEntry extends AbstractEntry implements Entry{

    private List<Entry> entries;

    private String path;

    public CompositeEntry(String path) {
        this.entries = Stream.of(StrUtil.split(path, File.pathSeparator))
                .map(e -> create(e)).collect(Collectors.toList());
        this.path = path;
    }


    @Override
    public byte[] readClass(String className) {

        for (Entry entry : entries) {
            try {
                return entry.readClass(className);
            } catch (Exception ignored) {

            }
        }
        throw new RuntimeException("class not found: " + className);
    }



}
